package Util

import (
	"time"
)

/**
 * Created by Goland
 * User: wkk alisleepy@hotmail.com
 * Time: 2021/12/17 - 02:08
 * Desc: <time相关方法处理>
 */

/*------------------ 时间处理  start---------------------*/

// DateTime 自定义Datetime
type DateTime time.Time

const (
	timeFormat = "2006-01-02 15:04:05"
)

func (t *DateTime) UnmarshalJSON(data []byte) (err error) {
	now, err := time.ParseInLocation(`"`+timeFormat+`"`, string(data), time.Local)
	*t = DateTime(now)
	return err
}

func (t DateTime) MarshalJSON() ([]byte, error) {
	b := make([]byte, 0, len(timeFormat)+2)
	b = append(b, '"')
	b = time.Time(t).AppendFormat(b, timeFormat)
	b = append(b, '"')
	return b, nil
}

func (t DateTime) String() string {
	return time.Time(t).Format(timeFormat)
}

/*------------------ 时间处理  end---------------------*/

func GetCurrentTimeStr() {
	// todo 后续再加
}

// ParseTime2Str 将time.Time格式的时间转换为 2022-02-06 14:00:03格式
//func ParseTime2Str(time time.Time) string {
//	tt, _ := time.Parse("2006-01-02T15:04:05Z07:00", time)
//
//	//格式化时间
//	return tt.Format("2006-01-02 15:04:05")
//}
